<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWechatUploadsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('wechat_uploads', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->char('key', 100)->default('')->comment('文件名的key');
            $table->string('title', 30)->default('未命名')->comment('文件标题');
            $table->decimal('duration', 12, 6)->default('0')->comment('媒体时长(秒)');
            $table->decimal('min_price', 6, 2)->default('2')->comment('最低打赏价格');
            $table->decimal('max_price', 6, 2)->default('2')->comment('最高打赏价格');
            $table->char('openid', 64)->default('')->comment('openid');
            $table->tinyInteger('status', false, true)->default('0')->comment('0-正常，1-隐藏，2-命名中');
            $table->tinyInteger('type', false, true)->default('0')->comment('1-图片，2-视频');
            $table->integer('buy_count', false, true)->default('0')->comment('购买次数');
            $table->integer('up', false, true)->default('0')->comment('点赞次数');
            $table->integer('down', false, true)->default('0')->comment('踩坑次数');
            $table->decimal('total_price', 12,2)->default('0')->comment('购买总额');
            $table->tinyInteger('qiniu_ready', false,true)->default('0')->comment('0-处理中，1-就绪');
            $table->char('promote_url', 64)->default('')->comment('推广链接');
            $table->dateTime('created_at')->nullable();
            $table->dateTime('updated_at')->nullable();
            $table->dateTime('deleted_at')->nullable();
            $table->index(['key', 'openid', 'status', 'type', 'qiniu_ready']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (Schema::hasTable('wechat_uploads')) {
            Schema::drop('wechat_uploads');
        }

    }
}
